<div class="container uicomponent">
<h1>Available Websites <small>(<a href="#edit-site">add new</a>)</small></h1>
<div class="content">
<div class="datagrid">
<div class="content">
<table class="zebra">
	<thead><tr>
		<th scope="col" width="15">#</th>
		<th scope="col">Websites</th>
		<th scope="col" width="200">Actions</th>
	</tr></thead>
	<tbody>
<?php 	
	foreach ( $sites as $site ): ?>
	<tr>
		<td><?php echo $site->site_id; ?></td>
		<td><strong><?php echo $site->site_name; ?></strong><br /><?php echo $site->site_url; ?><br /><?php if ( strcmp($hasCode[$site->site_id], 'n') == 0 ): echo '<span class="warning">This website does not include Cinnamon tracking code. <a href="sites.php?action=help&site_id='. $site->site_id .'">More &raquo;</a></span>'; endif; ?></td>
		<td><button onclick="location.href='sites.php?action=edit&amp;site_id=<?php echo $site->site_id; ?>';">Edit</button> <button onclick="location.href='sites.php?action=delete&amp;site_id=<?php echo $site->site_id; ?>';" class="delete">Delete</button> <button onclick="showCodeFor(<?php echo $site->site_id; ?>, '<?php echo $site->site_name; ?>');">Code</button></td>
	</tr>
<?php endforeach; ?>						
	</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="form" id="site-code" style="display: none;">
<h1></h1>
<div class="content">
<p>Copy and Paste the following line of code between the <code>head</code> tag in your pages:<br />(Select to highlight)</p>
<form name="codeForm" action="" id="codeForm">
<input type="text" value="" name="code" id="codeInput" size="120" /></form>
<p class="buttons"><button id="site-code-more-help">I need more help &raquo;</button> <button id="ok-done">OK, Done!</button></p>
</div>
</div> 
<script type="text/javascript">
function showCodeFor(id, name) {
	$('div#site-code > h1').html('Tracking-code for &ldquo;'+ name +'&rdquo;');
	$('input[@name=code]').val('<script type="text/javascript" src="<?php echo CSEURL; ?>/cse-javascript.php?site_id='+ id +'"><\/script>');
	$('input#codeInput').click( function() {
		document.getElementById('codeInput').focus();
		document.getElementById('codeInput').select();
	} );
	$('button#site-code-more-help').click( function() {
		location.href = 'sites.php?action=help&site_id='+ id;
	} );
	$('button#ok-done').click( function() {
		$('div#site-code').hide();
	} );
	$('div#site-code').toggle();
}
</script>
